package com.view;

import com.model.Anggota;
import com.model.Perpustakaan;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class PanelCariAnggota extends JPanel {

//    public static void main(String[] args) {
//        Anggota tes = new Anggota();
//        Scanner input = new Scanner(System.in);
//        System.out.println("Nama yang akan dicari : ");
//        String nama = input.next();
//        tes.setNama(nama);
//    }
    private JLabel labelCari, labelJudul;
    private JTextField textCari;
    private JButton simpan;
    private JButton hapus;

    public PanelCariAnggota() {
        setLayout(null);

        labelJudul = new JLabel("Panel Cari Anggota");
        labelJudul.setBounds(135, 10, 400, 40);
        labelJudul.setFont(new Font("Dialog", Font.TYPE1_FONT, 20));
        add(labelJudul);

        labelCari = new JLabel("Nama Anggota : ");
        labelCari.setBounds(25, 100, 200, 50);
        add(labelCari);
        textCari = new JTextField();
        textCari.setBounds(150, 110, 150, 30);
        add(textCari);

        simpan = new JButton("Simpan");
        simpan.setBounds(100, 300, 83, 26);
        add(simpan);
        simpan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                simpanAction();
            }
        });

        hapus = new JButton("Hapus");
        hapus.setBounds(250, 300, 70, 26);
        add(hapus);
        hapus.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == hapus) {
                    textCari.setText("");
                }
            }
        });
    }

    public void simpanAction() {
        Anggota anggota = new Anggota();
        anggota.setNama(textCari.getText());
        JOptionPane.showMessageDialog(this,"Telah Tersimpan, Silahkan cek Hasil Pada Tabel");
        Perpustakaan.cariAnggota(textCari.getText());
    }
}
